/**
 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.hellodoctor.slayer.service.impl;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;

import com.hellodoctor.slayer.model.Appointment;
import com.hellodoctor.slayer.service.base.AppointmentServiceBaseImpl;
import com.hellodoctor.util.LConstants;
import com.liferay.portal.kernel.exception.SystemException;

/**
 * The implementation of the appointment remote service.
 *
 * <p>
 * All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link com.hellodoctor.slayer.service.AppointmentService} interface.
 *
 * <p>
 * This is a remote service. Methods of this service are expected to have security checks based on the propagated JAAS credentials because this service can be accessed remotely.
 * </p>
 *
 * @author Shahbaj
 * @see com.hellodoctor.slayer.service.base.AppointmentServiceBaseImpl
 * @see com.hellodoctor.slayer.service.AppointmentServiceUtil
 */
public class AppointmentServiceImpl extends AppointmentServiceBaseImpl {

	public List<Appointment> getDaysTimeSlots(long doctorId, long patientId,
			String date) {

		List<Appointment> appointments = new ArrayList<Appointment>();
		DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
		dateFormat.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles")); 
		Date newDate = new Date();

		try {
			newDate = dateFormat.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		try {
			appointments = appointmentPersistence.findByDoctorId_ADate_status(
					doctorId, newDate, LConstants.Appointment_Status_Confirmed);
		} catch (SystemException e1) {
			e1.printStackTrace();
		}

		System.out.println("Inside remote service....." + appointments.size());
		
		return appointments;
	}
	
	public List<Appointment> getPatientAppointments(long patientId){
		List<Appointment> appts = new ArrayList<Appointment>();
		try {
			appts = appointmentPersistence.findByPatientId(patientId);
		} catch (SystemException e) {
			e.printStackTrace();
		}
		
		return appts;
	}
}